<?php

namespace App\ZL;

class ResponseLayout
{
    public static function apply($code,$data=[],$message='',$other=array())
    {
        $res = [];
        $res['data'] = null;
        if($data)   $res['data'] = $data;
        if(is_numeric($code)){
            $res['status'] = $code;
        }else{
            $res['status'] = $code?1:0;
        }
        if($message===''){
            if($res['status']==1){
                $res['msg'] = '操作成功';
            }else{
                $res['msg'] = '操作失败';
            }
        }else{
            $res['msg'] = $message;
        }
        if(!empty($other)){
            $res = array_merge($res,$other);
        }
        return $res;
    }

    public function flowReturn($res,$errcode,$errmsg,$msg)
    {
        if(!$errcode){
            $data['status'] = 1;
            $data['data'] = $res;
            $data['msg'] = $msg?$msg:'Success';
        }else{
            $data['status'] = $errcode;
            $data['data'] = null;
            $data['msg'] = $errmsg?$errmsg:'error';
        }
        return ['response'=>$data];
    }
}